<template>
  <div style="margin-right:50px;">
    <el-form :model="ruleForm" status-icon label-width="180px" class="demo-ruleForm" 
      style="margin-top: 50px;" size="mini">
      <el-row>
        <el-col :span="8">
          <el-form-item label="产品组合:" prop="prof">
          <el-input v-model="ruleForm.prof" autocomplete="off"></el-input>
        </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="产品/SPV:" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="产品/SPV余额(元):" prop="pass">
            <el-input v-model="ruleForm.pass" autocomplete="off"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="资金账号:" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="资金账户名称:" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="开户行名称:" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="开户行行号:" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="收息日期:" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="收息金额(元):" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="8">
          <el-form-item label="备注:" prop="age">
            <el-input v-model="ruleForm.age"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div style="text-align:center">
        <el-button type="success" @click="submitForm('ruleForm')">提交</el-button>
        <el-button type="info" @click="resetForm('ruleForm')">重置</el-button>
        <el-button type="info" @click="index()">重置</el-button>
      </div>
    </el-form>
  </div>
</template>
<script>
  export default {
    name:'index2',
    data() {
      var checkAge = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('年龄不能为空'));
        }
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error('请输入数字值'));
          } else {
            if (value < 18) {
              callback(new Error('必须年满18岁'));
            } else {
              callback();
            }
          }
        }, 1000);
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          pass: '',
          checkPass: '',
          age: ''
        },
        rules: {
          prof:[
            {required: true,message: '请输入投资组合', trigger: 'blur' }
          ],
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          age: [
            { validator: checkAge, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      index2(){
        alert(this.ruleForm.age);
      }
    }
  }
</script>

<style scoped>
</style>
